package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyBalanceAddDTO;
import org.jsola.hr.dto.CompanyBalanceUpdateDTO;
import org.jsola.hr.entity.CompanyBalanceDO;
import org.jsola.hr.query.CompanyBalanceQuery;
import org.jsola.hr.service.ICompanyBalanceService;
import org.jsola.hr.vo.CompanyBalanceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 用工单位账面余额表
 *
 * @author zhr
 */
@Component
public class CompanyBalanceTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyBalanceService companyBalanceService;

    /**
     * 生成add测试数据
     * @return CompanyBalanceAddDTO
     */
    public CompanyBalanceAddDTO getCompanyBalanceAddDTO(){
        CompanyBalanceAddDTO companyBalanceAddDTO = new CompanyBalanceAddDTO();
        companyBalanceAddDTO.setCompanyId(getRandomValue("varchar",32));
        companyBalanceAddDTO.setAmount(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        return companyBalanceAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyBalanceUpdateDTO
     */
    public CompanyBalanceUpdateDTO getCompanyBalanceUpdateDTO(CompanyBalanceVO companyBalanceVO){
        return companyBalanceService.selectDOById(companyBalanceVO.getId(), SITE_ID).to(CompanyBalanceUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyBalanceQuery
     */
    public CompanyBalanceQuery getCompanyBalanceQuery() {
        CompanyBalanceQuery companyBalanceQuery = new CompanyBalanceQuery();
        List<CompanyBalanceDO> companyBalanceDOList = companyBalanceService.list(new CompanyBalanceDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyBalanceDOList)) {
            CompanyBalanceDO companyBalanceDO = companyBalanceDOList.get(0);
            companyBalanceQuery = companyBalanceDO.to(CompanyBalanceQuery.class);
            if (companyBalanceDO.getGmtCreate() != null) {
                companyBalanceQuery.setGmtCreateStart(DateKit.getBeforeDay(companyBalanceDO.getGmtCreate(),-1));
                companyBalanceQuery.setGmtCreateEnd(DateKit.getBeforeDay(companyBalanceDO.getGmtCreate(),1));
            }
        }
        return companyBalanceQuery;
    }

    /**
     * 保存示例
     * @return CompanyBalanceVO
     */
    public CompanyBalanceVO saveCompanyBalanceExample(){
        CompanyBalanceAddDTO addDTO = this.getCompanyBalanceAddDTO();
        CompanyBalanceVO companyBalanceVO = companyBalanceService.save(addDTO,buildTokenUser());
        return companyBalanceVO;
    }


}

